# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl

mpl.rcParams['font.sans-serif'] = ['SimHei']  
mpl.rcParams['axes.unicode_minus']=False

from HelperClass2.NeuralNet_2_2 import *
from HelperClass2.Visualizer_1_1 import *
from HelperClass2.DataReader_2_0 import *
from HelperClass2.HyperParameters_2_0 import *

train_data_name = "train.npz"
test_data_name = "test.npz"

if __name__ == '__main__':
    dataReader = DataReader_2_0(train_data_name, test_data_name)
    dataReader.ReadData()
    dataReader.NormalizeY(NetType.MultipleClassifier, base=1)

    # fig = plt.figure(figsize=(6,6))
    # DrawThreeCategoryPoints(dataReader.XTrainRaw[:,0], dataReader.XTrainRaw[:,1], dataReader.YTrain, title="源数据")
    # plt.show()

    dataReader.NormalizeX()
    dataReader.Shuffle()
    dataReader.GenerateValidationSet()

    n_input = dataReader.num_feature  # 2
    n_hidden = 4
    n_output = dataReader.num_category  # 3
    eta, batch_size, max_epoch = 0.2, 23, 15000
    eps = 0.1

    hp = HyperParameters_2_0(n_input, n_hidden, n_output, eta, max_epoch, batch_size, eps, NetType.MultipleClassifier, InitialMethod.Xavier)
    net = NeuralNet_2_2(hp, "Bank_233")

    # net.LoadResult()  # 加载模型（已有的神经网路权值和偏置）


    net.train(dataReader, 100, True)
    net.ShowTrainingHistory()

    fig = plt.figure(figsize=(6,6))
    DrawThreeCategoryPoints(dataReader.XTrain[:,0], dataReader.XTrain[:,1], dataReader.YTrain, hp.toString())
    ShowClassificationResult25D(net, 100, hp.toString())
    plt.show()
